<form class="layui-form layui-card" action="{:request()->url()}" data-auto="true" method="post" autocomplete="off">
    <div class="layui-card-body padding-left-40">
        <div class="layui-form-item">
            <label class="relative block">
                <span class="color-green font-w7">登录用户账号</span>
                <span class="color-desc margin-left-5">Username</span>
                {if isset($vo) and isset($vo.username)}
                <input disabled value='{$vo.username|default=""}' class="layui-input layui-bg-gray">
                {else}
                <input name="username" value='{$vo.username|default=""}' required pattern="^.{4,}$" placeholder="请输入4位及以上字符登录用户账号" class="layui-input">
                {/if}
            </label>
            <p class="help-block">登录用户账号创建后，不允许再次修改。</p>
        </div>
        
         <div class="layui-form-item">
            {if $auth_id eq 6 }
            <label class="relative block">
                <span class="color-green font-w7">市代理</span>
                <span class="color-desc margin-left-5">City agency</span>
                <div class="layui-input-block">
                    <select name="region_id" lay-verify="required">
                        <option value="">请选择市代理</option>
                        {foreach $regionCity as $item}
                        <option value="{$item.id}">{$item.title}</option>
                        {/foreach}
                    </select>
                </div>
            </label>
            <p class="help-block">绑定市代理。</p>
            {else/}
            <label class="relative block">
                <span class="color-green font-w7">区代理</span>
                <span class="color-desc margin-left-5">Area agency</span>
                <div class="layui-input-block">
                    <select name="region_id" lay-verify="required" >
                        <option value="">请选择区代理</option>
                        {foreach $regionCity as $item}
                        <optgroup label="{$item.title}">
                            {foreach $item.son as $itemSon}
                            <option value="{$itemSon.id}">{$itemSon.title}</option>
                            {/foreach}
                        </optgroup>
                        {/foreach}
                        
                    </select>
                </div>
            </label>
            <p class="help-block">绑定区代理。</p>
            {/if}
        </div>
        
        {notempty name='authorizes'}
        <div class="layui-form-item relative">
            <span class="color-green font-w7">角色访问授权</span>
            <span class="color-desc margin-left-5">Authorization</span>
            <div class="layui-textarea">
                {if isset($vo.username) and $vo.username eq 'admin'}
                <span class="color-desc">超级用户不需要配置权限</span>
                {elseif empty($authorizes)}
                <span class="color-desc">未配置权限</span>
                {else}
                {foreach $authorizes as $authorize}
                    {if Session('store')}
                        {if $authorize.id neq 1}
                        <label class="think-checkbox layui-unselect">
                            {if in_array($authorize.id, $vo.authorize)}
                            <input type="checkbox" checked name="authorize[]" value="{$authorize.id}" lay-ignore> {$authorize.title}
                            {else}
                            <input type="checkbox" name="authorize[]" value="{$authorize.id}" lay-ignore> {$authorize.title}
                            {/if}
                        </label>
                        <input style="display: none;" type="input" name="store_id" value="{$Think.session.store.id}" lay-ignore>
                     {/if}
                    {else /}
                        <label class="think-checkbox layui-unselect">
                            {if in_array($authorize.id, $vo.authorize)}
                            <input type="checkbox" checked name="authorize[]" value="{$authorize.id}" lay-ignore> {$authorize.title}
                            {else}
                            <input type="checkbox" name="authorize[]" value="{$authorize.id}" onclick="onClickHander(this)" lay-ignore> {$authorize.title}
                            {/if}
                        </label>
                    {/if}
                {/foreach}
                {/if}
            </div>
        </div>
        {/notempty}
        
    </div>

    <div class="hr-line-dashed"></div>
    {notempty name='vo.id'}<input type='hidden' value='{$vo.id}' name='id'>{/notempty}

    <div class="layui-form-item text-center">
        <button class="layui-btn" type='submit'>保存数据</button>
        <button class="layui-btn layui-btn-danger" type='button' data-confirm="确定要取消编辑吗？" data-close>取消编辑</button>
    </div>

</form>

<script>
    form.render('select')
    form.render('optgroup')
</script>